#include <vector>
#include <algorithm>
using namespace std;
/*
 * @lc app=leetcode.cn id=26 lang=cpp
 *
 * [26] 删除有序数组中的重复项
 */

// @lc code=start
class Solution {
public:
    // 0 1 2 3 1 0 2 1 3 4
    /*
    int removeDuplicates(vector<int>& nums) {
        int i = 0, j  = 1;
        while (j < nums.size()) {
            while (j < nums.size() && nums[j] == nums[i]) {
                j++;
            }
            if (j == nums.size()) break;
            nums[i + 1] = nums[j];
            i++; j++;
        }
        return i + 1;
    }
    */

   // 0,0,1,1,1,2,2,3,3,4
   int removeDuplicates(vector<int>& nums) {
        int i = 0, j  = 1;
        while (j < nums.size()) {
            if (nums[i] == nums[j]) j++;
            else {
                i++; nums[i] = nums[j];
                j++;
            }
        }
        return i + 1;
    }

};
// @lc code=end

